﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Mindfor.Web
{
	/// <summary>
	/// If action returns JsonResult then JsonRequestBehaviour is set to AllowGet.
	/// </summary>
	[AttributeUsage(AttributeTargets.Method, Inherited=true, AllowMultiple=false)]
	public class JsonAllowGetAttribute : ActionFilterAttribute
	{
		/// <summary>
		/// Called by the MVC framework after the action method executes.
		/// </summary>
		/// <param name="filterContext">The filter context.</param>
		public override void OnActionExecuted(ActionExecutedContext filterContext)
		{
			if (filterContext.Result is JsonResult)
			{
				JsonResult result = (JsonResult)filterContext.Result;
				result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
			}
			base.OnActionExecuted(filterContext);
		}
	}
}
